<template>
  <div class="rack-container" draggable @dragstart="rackDragStart(rackItem, $event)">
    <div class="rack">
      <div 
        class="panel-head"
        @mouseenter="mouseEnterTitle($event)"
        @mouseleave="mouseLeaveTitle($event)"
      >
        <span class="panel-head-title" :title="rackItem.name">{{rackItem.name}}</span>
        <span class="operate-icon-box">
          <!-- <i class="icon icon-edit16f operate-icon" @click="openEditInput($event)"></i> -->
					<Iconfont class="icon operate-icon" type="icon-edit16f" @click="openEditInput($event)"></Iconfont>
          <!-- <i class="icon icon-delete16f operate-icon" @click="deleteBox(rackItem, $event)"></i> -->
					<Iconfont class="icon operate-icon" type="icon-delete16f" @click="deleteBox(rackItem, $event)"></Iconfont>
        </span>
      </div>
      <div class="data-center-name-input">
        <a-input :defaultValue="rackItem.name">
          <a-tooltip slot="suffix" title="请输入合法的名称（ 1 ~ 128 个字符，支持大小写字母、数字、句点（.）、下划线（_）和连字符（-））">
            <a-icon type="info-circle" style="color: rgba(0,0,0,.45)" />
          </a-tooltip>
        </a-input>
        <a-icon type="check-square" theme="filled" class="input-operate-icon theme-color" @click="handleEditInputName($event)"/>
        <a-icon type="close-square" theme="filled" class="input-operate-icon" @click="cancelEditInputName($event)"/>
      </div>
      <div class="panel-body">
        <div
          v-for="(nodeItem,index4) in rackItem.children"
          class="machine" 
          draggable
          :key="'out-node'+index4"
          @dragstart="nodeDragStart(nodeItem, $event)"
        >
          <p class="host-name">
            <span class="green-circle"></span>
            <span class="node-name" :title="nodeItem.name">{{nodeItem.name}}</span>
          </p>
          <p class="host-ip" :title="nodeItem.ip">
            <span class="node-ip">{{nodeItem.ip}}</span>
          </p>
        </div>
        <!-- 机器虚线提示区域 -->
        <div 
          v-if="nowPlacementRackDom && currentTool=='node' 
          && nowPlacementRackDom.textContent.indexOf(rackItem.name) !== -1
          && nowPlacementRackDom.textContent != nowDragRackDom.textContent"
          class="dashed-machine"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "RackBox",
  props: ['rackItem', 'nowPlacementRackDom', 'currentTool', 'nowDragRackDom'],

  data() {
    return {
      
    }
  },

  methods: {
    mouseEnterTitle(e) {
      this.$emit('mouseEnterTitle', e);
    },

    mouseLeaveTitle(e) {
      this.$emit('mouseLeaveTitle', e);
    },

    openEditInput(e) {
      this.$emit('openEditInput', e);
    },

    deleteBox(delItem, e) {
      this.$emit('deleteBox', delItem, e);
    },

    handleEditInputName(e) {
      this.$emit('handleEditInputName', e);
    },

    cancelEditInputName(e) {
      this.$emit('cancelEditInputName', e);
    },

    rackDragStart(item, e) {
      this.$emit('rackDragStart', item, e);
    },

    nodeDragStart(item, e) {
      this.$emit('nodeDragStart', item, e);
    },
  },
}
</script>
<style scoped>
  .machine p{
    margin: 3px 16px;
    color: #a2a3a9;
  }
  .node-ip {
    max-width: 150px;
    color: #3f3f44;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: bottom;
  }
  .panel-head {
    /* display: none; */
    display: flex;
    justify-content: space-between;
    padding: 8px 16px;
    color: #333;
    font-size: 14px;
    position: relative;
    line-height: 28px;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    background-color: var(--mainGreyColor);
  }
  .panel-head-title {
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: calc(100% - 50px);
  }
  .operate-icon {
    cursor: pointer;
    color: var(--themeColor);
    margin-left: 10px;
    font-size: 14px;
    visibility: hidden;
  }
  .input-operate-icon {
    font-size: 20px;
    vertical-align: middle;
    cursor: pointer;
    margin-left: 5px;
  }
  .theme-color {
    color: var(--themeColor);
  }
  .panel-body {
    display: flex;
    flex-wrap: wrap;
    padding: 8px 0 0 8px;
  }
  .rack-container > .rack > .panel-body  {
    flex-direction: row !important;
    padding: 0 6px 3px!important;
  }
  .rack .panel-body {
    padding: 0 6px 3px;
  }
  .rack-container {
    display: inline-block;
    /* min-width: 180px; */
    margin-left: 8px;
    margin-right: 16px;
    vertical-align: top;
  }

  .rack .data-center-name-input > .ant-input-affix-wrapper {
    display: inline-block;
    width: 90px;
  }
  .data-center-name-input {
    /* display: inline-block; */
    display: none;
    padding: 8px 16px;
  }
  .data-center-name-input > .ant-input-affix-wrapper {
    display: inline-block;
    width: 186px;
  }
  .dashed-rack {
    min-width: 148px;
    min-height: 105px;
    border-radius: 3px;
    margin-right: 8px;
    margin-bottom: 16px;
    background-color: transparent;
    box-shadow: none;
    border: 2px dashed #e6e6e6;
  }
  .rack {
    min-width: 148px;
    max-width: 180px;
    min-height: 105px;
    border-radius: 3px;
    margin-right: 8px;
    margin-bottom: 16px;
    background-color: var(--mainGreyColor);
    box-shadow: none;
    border: 1px solid #e6e6e6;
  }
  .dashed-machine {
    width: 150px;
    min-height: 49px;
    border: 2px dashed #fff;
    margin: 0 0 5px;
    border-radius: 2px;
  }
  .machine {
    width: 150px;
    border: 1px solid rgba(0,0,0,0);
    margin: 0 0 5px;
    border-radius: 2px;
    background-color: #fff;
    font-size: 12px;
    cursor: pointer;
  }
  .machine:hover {
    border: 1px solid var(--themeColor);
  }
  .rack-box-selected,
  .machine-box-selected {
    border: 1px solid var(--themeColor);
  }
  .clearfix {
    width: 100%;
  }
  .clearfix:after, .clearfix:before {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both;
  }
</style>